package com.cuzofu.fs.common;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.io.Serializable;
import java.util.List;

/**
 * 分页工具类
 *
 * @author cuzofu
 */
public class PageUtils implements Serializable {
    private static final long serialVersionUID = 1L;

    private boolean success;
    /**
     * 总记录数
     */
    private int total;
    /**
     * 每页记录数
     */
    private int pageSize;
    /**
     * 总页数
     */
    private int page;
    /**
     * 当前页数
     */
    private int current;
    /**
     * 列表数据
     */
    private List<?> data;

    /**
     * 分页
     *
     * @param data     列表数据
     * @param total    总记录数
     * @param pageSize 每页记录数
     * @param current  当前页数
     */
    public PageUtils(List<?> data, int total, int pageSize, int current) {
        this.success = true;
        this.data = data;
        this.total = total;
        this.pageSize = pageSize;
        this.current = current;
        this.page = (int) Math.ceil((double) total / pageSize);
    }

    /**
     * 分页
     */
    public PageUtils(IPage<?> page) {
        this.success = true;
        this.data = page.getRecords();
        this.total = (int) page.getTotal();
        this.pageSize = (int) page.getSize();
        this.current = (int) page.getCurrent();
        this.page = (int) page.getPages();
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public List<?> getData() {
        return data;
    }

    public void setData(List<?> data) {
        this.data = data;
    }
}
